package com.functest.util

/**
 * @author: DavydovMD
 * Date: 16.04.13
 * Time: 18:54
 */

class EnumUtils {
    public static <T> Closure<T> fromCodeClosure(Class<T> clazz) {
        return { int code ->
            try {
                return (clazz.invokeMethod("values", null) as List<T>).grep { it.code == code }.last()
            } catch (NoSuchElementException ignored) {
                throw new UnsupportedOperationException("Unsupported code:${code} in ${clazz}")
            }
        }
    }
}
